sysdir set PERSONAL "I:\MAA2015-20 Credit and Education\stata"
do "I:\MAA2015-20 Credit and Education\stata\outreg2.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdrobust.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdplot.ado"


*Appendix Table C1
use "basesample_earn.dta",clear
set more off
set matsize 10000
preserve
*Based on Appendix Table A1, we drop 57 top earnings females to obtain bounded estimates
count if  avg_was_post5yr>=5550& female==1&ratio_pass>=0.5 &ratio_pass<=0.65
drop if avg_was_post5yr>=5550&female==1&ratio_pass>=0.5 &ratio_pass<=0.65
gen lnavg_was_post5yr=log(avg_was_post5yr)

*columns 1-2 
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {
 
rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 
}
}
}

restore
*Donut estiamtes
*Columns 3-4
drop if ratio_pass>0.485&ratio_pass<0.515 
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
}
*Donut estiamtes
*Columns 5-6
drop if ratio_pass>0.47&ratio_pass<0.53 
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist  avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC1,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
}
 
 
*Appendix Table C2
 
use "basesample_earn.dta",clear
set more off
set matsize 10000

forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.10 0.10) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC2,excel dec(2) 

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.20 0.20) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC2,excel dec(2) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.10 0.10) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC2,excel dec(2) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.20 0.20) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC2,excel dec(2) 

}
}
} 


*Appendix Table C3
 
use "basesample_earn.dta",clear
set more off
set matsize 10000
preserve
keep if science ==1 
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
} 
restore
preserve
keep if business == 1
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
} 

restore
drop if business==1
drop if science ==1

forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y'  ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC3,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
} 


*Appendix Table C4
*Columns 1 & 4
use "basesample_earn.dta",clear
set more off
set matsize 10000
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i', c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC4,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
} 

*Columns 2-3 & 5-6
use "basesample_earn_08.dta",clear
set more off
set matsize 10000

forv i = 0(1)1 {
forv l = 0(1)5 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'y{

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2001-cohort2004 year2002-year2005)
outreg2 using TableC4,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r))

}
}
}

*Appendix Table C5
use "basesample_earn.dta",clear
set more off
set matsize 10000
preserve
keep if year==2010

forv i = 1(1)1 {
forv l = 5(1)7 {

foreach y of varlist avg_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.10) b(0.20) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008 )
outreg2 using TableC5,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r))

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.20) b(0.40) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008 )
outreg2 using TableC5,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r))

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.10) b(0.20) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008 )
outreg2 using TableC5,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r))

rdrobust `y' ratio_pass if female == `i' , c(0.5) h(0.20) b(0.40) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008 )
outreg2 using TableC5,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r))

}
}
}


*Appendix Table C6
use "basesample_earn.dta",clear
set more off
set matsize 10000

*Upper panel for female students
forv l = 0(1)7 {
gen log_was_post`l'yr=log(avg_was_post`l'yr )
} 
 
forv i = 1(1)1 {
forv l = 5(1)5 {

foreach y of varlist log_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i' &was_percent_post`l'yr>0, c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC6,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i'&was_percent_post`l'yr>0 , c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008-cohort2010 year2011-year2012)
outreg2 using TableC6,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
}

*Lower panel for female students assessed in 2010
keep if year == 2010
forv i = 1(1)1 {
forv l = 5(1)7 {

foreach y of varlist log_was_post`l'yr was_percent_post`l'yr {

rdrobust `y' ratio_pass if female == `i' &was_percent_post`l'yr>0, c(0.5) h(0.15) b(0.30) fuzzy(treat) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using TableC6,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

rdrobust `y' ratio_pass if female == `i'&was_percent_post`l'yr>0 , c(0.5) h(0.15) b(0.30) fuzzy(loan) covs(age maori disable full decile science business provider7001-provider7008 cohort2008)
outreg2 using TableC6,excel dec(2) adds(bw obs l, e(N_h_l), bw obs r,e(N_h_r)) 

}
}
}


*Appendix Table C7
use "basesample_earn.dta",clear
set more off
set matsize 10000

capture program drop kratio
program kratio,rclass
version 13
args ky y
confirm var `ky'
confirm var `y'
tempname kymean ymean
sum `ky',meanonly
scalar `kymean'= r(mean)
sum `y',meanonly
scalar `ymean'=r(mean)
return scalar ratio=`kymean'/`ymean'
end
return list

*Column 1 is the same as Column 1 in Table 1
*Column2
foreach y of varlist female age maori white asian disable full uni decile science business loan_amt percentile {
reg treat `y' if ratio_pass>=0.35&ratio_pass<=0.65
predict treat_`y' if e(sample),xb
gen k_`y'=1-(loan*(1-treat)/(1-treat_`y'))- ((1-loan)*treat/treat_`y')
gen k_`y'Y=k_`y'*`y'
bs ratio=r(ratio),r(500):kratio k_`y'Y k_`y'
outreg2 using tableC7,excel dec(2)
}

*Column 3
keep if female == 1
reg ratio_pass age maori white disable full uni business science loan_amt decile if ratio_pass>=0.35&ratio_pass<=0.65
outreg2 using TableC7, excel dec(2) cttop(all) sum  

reg ratio_pass percent if ratio_pass>=0.35&ratio_pass<=0.65 
outreg2 using TableC7, excel dec(2) cttop(all) sum  

*Column4
foreach y of varlist age maori white asian disable full uni decile science business loan_amt percentile {
reg treat `y' if ratio_pass>=0.35&ratio_pass<=0.65
predict treat_`y' if e(sample),xb
gen k_`y'=1-(loan*(1-treat)/(1-treat_`y'))- ((1-loan)*treat/treat_`y')
gen k_`y'Y=k_`y'*`y'
bs ratio=r(ratio),r(500):kratio k_`y'Y k_`y'
outreg2 using TableC7,excel dec(2)
}


*Figure C1

use "basesample_earn.dta",clear
set more off
set matsize 10000
keep if female==0

*Upper panels
rdplot avg_was_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(1500(500)3500) title("Monthly Earnings, 5 Years After Assessment (2001-2005 Male)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_post5yr_male_08.gph", replace
graph export "was_post5yr_male_08.png", as(png) replace

rdplot was_percent_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(20(10)60) title("Earnings Percentile, 5 Year After Assessment (2001-2005 Male)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_percent_post5yr_male_08.gph", replace
graph export "was_percent_post5yr_male_08.png", as(png) replace

use "basesample_earn_08.dta",clear
set more off
set matsize 10000
preserve
*Middle panels
keep if female==1
rdplot avg_was_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(1000(500)3000) title("Monthly Earnings, 5 Years After Assessment (2001-2005 Female)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_post5yr_female_08.gph", replace
graph export "was_post5yr_female_08.png", as(png) replace

rdplot was_percent_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(20(10)60) title("Earnings Percentile, 5 Year After Assessment (2001-2005 Female)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_percent_post5yr_female_08.gph", replace
graph export "was_percent_post5yr_female_08.png", as(png) replace

restore
*Lower Panels
keep if female==0

rdplot avg_was_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(1500(500)3500) title("Monthly Earnings, 5 Years After Assessment (2001-2005 Male)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_post5yr_male_08.gph", replace
graph export "was_post5yr_male_08.png", as(png) replace

rdplot was_percent_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15) p(1) c(0.5)  graph_options(ylabel(20(10)60) title("Earnings Percentile, 5 Year After Assessment (2001-2005 Male)", size(median large)) xtitle("Pass Rates") graphregion(color(white)))
graph save Graph "was_percent_post5yr_male_08.gph", replace
graph export "was_percent_post5yr_male_08.png", as(png) replace


